
const Koa = require('koa');
const app = new Koa();
const path = require('path');
const koaStatic = require('koa-static');
const Router = require('koa-router');
const router = new Router();
const fs = require('fs')
const proxy = require('koa-server-http-proxy')

let proxyFront = {
  target: 'http://edufront.lagou.com',
  changeOrigin: true,
};
let proxyBoss = {
  target: 'http://eduboss.lagou.com',
  changeOrigin: true,
};

app.use(koaStatic(
  path.join(__dirname, './dist')
));

app.use(proxy('/front', proxyFront))
app.use(proxy('/boss', proxyBoss))

router.get('/(.*)', async ctx => {
  console.log(ctx.URL)
  ctx.type = "text/html;charset=utf-8"
  const res = fs.readFileSync(path.join(__dirname, 'dist/index.html'), 'utf-8')
  ctx.body = res
})


app.use(router.routes()).use(router.allowedMethods());

app.listen(8001, () => {
    console.log(`Node server has been started on http://localhost:8001`)
});
